package org.example.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author weigang
 * @create 2022-10-31 10:15
 */
@AllArgsConstructor
@Getter
public enum ConfirmedStateEnum {
    /**
     * 已经确认，commit状态
     */
    CONFIRMED("confirmed", "Committed"),

    /**
     * 创建修改后，未commit
     */
    NOT_CONFIRMED("not_confirmed", "Draft"),

    /**
     * 等待审核
     */
    WAITING_CONFIRMED("waiting_confirmed", "UnderReview"),


    /**
     * 审核拒绝
     */
    CONFIRM_REJECTED("confirm_rejected", "Rejected"),

    /**
     * 审核撤回
     */
    REVOKED("confirm_revoked", "Withdrawn"),
    ;

    private String state;

    private String value;

    private static final Map<String, ConfirmedStateEnum> MAP = Arrays.stream(ConfirmedStateEnum.values())
            .collect(Collectors.toMap(ConfirmedStateEnum::getState, Function.identity()));

    public static ConfirmedStateEnum ofState(String state, ConfirmedStateEnum defaultEnum) {
        return MAP.getOrDefault(state, defaultEnum);
    }

    public static ConfirmedStateEnum ofState(String state) {
        return ofState(state, null);
    }
}
